package com.didojoy.lameliarary.utils;

import android.text.TextUtils;

import com.didojoy.lameliarary.Mp3Recorder;
import com.didojoy.lameliarary.jni.FlameUtils;

import java.io.File;

/**
 * Created by weiwei42 on 2018/1/22.
 */

public class Mp3Util {

    private static Mp3Util mInstance;
    private FlameUtils mUtils;

    private Mp3Util() {
        mUtils = new FlameUtils(Mp3Recorder.NUM_CHANNELS, Mp3Recorder.SAMPLE_RATE, Mp3Recorder.BITRATE);
    }

    public static Mp3Util getInstance() {
        if (mInstance == null) {
            synchronized (Mp3Util.class) {
                if (mInstance == null) {
                    mInstance = new Mp3Util();
                }
            }
        }
        return mInstance;
    }

    public boolean convertRaw2Mp3(File pcmFile, File mp3File) {
        return convertRaw2Mp3(pcmFile.getAbsolutePath(), mp3File.getAbsolutePath());
    }

    public boolean convertRaw2Mp3(String pcmPath, String mp3Path) {
        if (TextUtils.isEmpty(pcmPath) || TextUtils.isEmpty(mp3Path)) {
            return false;
        }
        return mUtils.raw2mp3(pcmPath, mp3Path);
    }

}
